﻿@{
    ViewBag.Title = "原材料库盘点单据信息";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var autoSearch = true;
    $(function () {
        initControl();
        gridList();
    });

    function initControl() {
        var FDocuNO = $.request("FDocuNO");
        if (!!FDocuNO) {
            $('#FDocuNO').val(FDocuNO);
        }
        var FDocuNOShow = $.request("FDocuNOShow");
        if (!!FDocuNOShow) {
            $('#FDocuNOShow').val(FDocuNOShow);
        }
        var FHappenComNO = $.request("FHappenComNO");
        if (!!FHappenComNO) {
            $('#FHappenComNO').val(FHappenComNO);
        }
        var FDescription = $.request("FDescription");
        if (!!FDescription) {
            $('#FDescription').val(FDescription);
        }
        var FDocuTypeNO = $.request("FDocuTypeNO");
        if (!!FDocuTypeNO) {
            $('#FDocuTypeNO').val(FDocuTypeNO);
        }
        var FCurDate = $.request("FCurDate");
        if (!!FCurDate) {
            $('#FCurDate').val(FCurDate);
        }
        var FCredence = $.request("FCredence");
        if (!!FCredence) {
            $('#FCredence').val(FCredence);
        }
        var FCertificateNo = $.request("FCertificateNo");
        if (!!FCertificateNo) {
            $('#FCertificateNo').val(FCertificateNo);
        }
        if (FDocuNO != '') {
            lockInputById("#item");
        }
        initBindSelect("#form1");

        initFStoreNO($('#FDocuTypeNO').val());
        initFStoreSetNO($("#FStoreNO").val());
        $('#FDocuTypeNO').on("change", function () {
            initFStoreNO($('#FDocuTypeNO').val());
            gridList();
        });
        $('#FStoreNO').on("change", function () {
            initFStoreSetNO($("#FStoreNO").val());
        });
        
        $('#FQuantity_KP').on("blur", function () {
            if ($('#FQuantity_KP').val() != '' && $('#FQuantity').val() == '') {
                $('#FQuantity').val($('#FQuantity_KP').val());
            }
        });
        $('#FZS_KP').on("blur", function () {
            if ($('#FZS_KP').val() != '' && $('#FZS').val() == '') {
                $('#FZS').val($('#FZS_KP').val());
            }
        });

        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                var actObj = document.activeElement.id;
                if ($('#FDocuTypeNO').val() == "LR" || $('#FDocuTypeNO').val() == "LC") {
                    if (actObj == "MaterialCode" || actObj == "FCertificateNo") {
                        gridReload2();
                    }
                } else {
                    if (actObj == "MaterialCode") {
                        gridReload1();
                    }
                }
            }
        });
    }
    function initFStoreNO(FDocuTypeNO) {
        $("#FStoreNO").empty();
        $("#FStoreNO").bindSelect({
            url: "/WareHouse/MaterialStore/GetStoreHouseListJson",
            id: "FStoreNO",
            text: "FStoreNoAndName",
            param: { FDocuTypeNO: FDocuTypeNO },
            search: false
        });
    }
    function initFStoreSetNO(storeNO) {
        $("#FStoreSetNO").empty();
        $("#FStoreSetNO").bindSelect({
            url: "/WareHouse/MaterialStore/GetStoreHouseSetListJson",
            id: "FStoreSetNO",
            text: "FStoreSetNO",
            param: { storeNO: storeNO },
            search: false
        });
    }
    function gridList() {
        gridList2();
    }
    function gridList2() {
        var $gridList = $("#gridList2");
        $gridList.dataGrid({
            url: "/WareHouse/MaterialStore/GetMaterialPro2ListJson",
            postData: { MaterialNO: $('#MaterialNO').val(), FVoucherNo: $('FCertificateNo').val(), MaterialCode: $('#MaterialCode').val() },
            height: 160,
            colModel: [
                { label: '合同编号', name: 'FVoucherNo', width: 120, align: 'left', sortable: false },
                { label: '捆包号', name: 'FBatch', width: 80, align: 'left', sortable: false },
                { label: '入库单号', name: 'FDocuNO', width: 80, align: 'left', sortable: false },
                { label: '供货单位编码', name: 'FProCompanyNO', width: 80, align: 'left', sortable: false },
                { label: '供货单位', name: 'FProCompanyName', width: 80, align: 'left', sortable: false },
                { label: '材料分类', name: 'MaterialName', width: 80, align: 'left', sortable: false },
                { label: '材料牌号', name: 'MaterialCode', width: 80, align: 'left', sortable: false },
                { label: '材料规格', name: 'MaterialSizes', width: 80, align: 'left', sortable: false },
                { label: '标准编号', name: 'StandardNumber', width: 80, align: 'left', sortable: false },
                { label: '特殊要求', name: 'MaterialDemand', width: 80, align: 'left', sortable: false },
                { label: '库存重量(kg)', name: 'FQuantity_KC', width: 80, align: 'left', sortable: false },
                { label: '库存张数', name: 'FZS_KC', width: 80, align: 'left', sortable: false },
                { label: '单价(元/kg)', name: 'FPrice', width: 80, align: 'left', sortable: false },
                { label: '仓库编码', name: 'FStoreNO', width: 80, align: 'left', sortable: false },
                { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left', sortable: false },
                { label: '库位编码', name: 'FStoreSetNO', width: 80, align: 'left', sortable: false },
                { label: '炉批号', name: 'FOvenNum', width: 80, align: 'left', sortable: false },
                { label: '出厂日期', name: 'WagonNumber', width: 80, align: 'left', sortable: false },
                { label: '材料分类(隐藏)', name: 'MaterialNO', width: 80, align: 'left', hidden: true },
            ],
            sortname: 'CGHTBH ASC,CGCLPH ASC,CGCLGG ASC',
            rownumWidth: 40,
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);

                $("#FSourceDouNO").val(rowData.FDocuNO);

                $('#MaterialNO').val(rowData.MaterialNO);
                $('#MaterialNO').bindSelect();
                $('#MaterialCode').val(rowData.MaterialCode);
                $('#MaterialSizes').val(rowData.MaterialSizes);
                $('#StandardNumber').val(rowData.StandardNumber);
                $('#MaterialDemand').val(rowData.MaterialDemand);
                $('#FProCompanyNO').val(rowData.FProCompanyNO);
                $('#FProCompanyNO').bindSelect();
                $('#FPrice').val(rowData.FPrice);
                $('#FCertificateNo').val(rowData.FVoucherNo);
                $('#FCredence').val(rowData.FVoucherNo);
                $('#FBatchNo').val(rowData.FBatch);
            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                }
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
    }
    function gridReload2() {
        var $gridList = $("#gridList2");
        $gridList.jqGrid('setGridParam', {
            postData: { MaterialNO: $('#MaterialNO').val(), FVoucherNo: $('FCertificateNo').val(), MaterialCode: $('#MaterialCode').val() },
        }).trigger('reloadGrid');
    }
    function btn_ok() {
        if (!$('#form1').formValid()) {

        } else {
            var param = $("#item").formSerialize();
            var detail = $(".detailForm").formSerialize();
            detail["FDescription"] = detail["FDescription2"];
            param["detail"] = JSON.stringify(detail);
            $.submitForm({
                url: "/WareHouse/MaterialStore/SubmitMaterialStoreInventoryForm?status=I",
                param: param,
                close: false,
                success: function (result) {
                    setDataByJson('#item', result.data);
                    if ($('#FDocuNO').val() != '') {
                        $('#FDocuNOShow').val($('#FDocuNO').val());
                    }
                    lockInputById("#item");
                    $('#FDescription').prop("disabled", false);
                    emptyDataById("#detail");
                    initBindSelect("#detail");
                    var father = $.currentSubSubWindow().frames["Detail"];
                    father.reloadPageData($("#item").formSerialize());
                }
            })
        }
    }
    function btn_cancel() {
        var father = $.currentSubSubWindow().frames["Detail"];
        father.$.detailCloseTop();
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div style="padding-top: 1px;margin-left:10px;margin-right:10px;">
        <form id="form1">
            <table id="item" class="form" style="margin:5px 0;">
                <tr>
                    <th class="formTitle" style="width:60px;">&nbsp;</th>
                    <td class="formValue" style="width:220px;">
                        &nbsp;
                    </td>
                    <th class="formTitle" style="width:60px;">&nbsp;</th>
                    <td class="formValue" style="width:220px;">
                        &nbsp;<input id="FDocuListID" name="FDocuListID" type="hidden" value="">
                    </td>
                    <th class="formTitle" style="width:60px;">单据编号</th>
                    <td class="formValue">
                        <input id="FDocuNOShow" name="FDocuNOShow" type="text" class="form-control" disabled="disabled" value="" />
                        <input id="FDocuNO" name="FDocuNO" type="hidden" value="">
                    </td>
                </tr>
                <tbody style="border: 1px solid #ddd;">
                    <tr>
                        <th class="formTitle" style="width:60px;">发生方式</th>
                        <td class="formValue" style="width:220px;">
                            <select id="FDocuTypeNO" name="FDocuTypeNO" class="form-control required">
                                @foreach (var item in ViewBag.fdocutypenoList)
                            {
                                    <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                            }
                            </select>
                        </td>
                        <th class="formTitle" style="width:60px;">单据日期</th>
                        <td class="formValue" style="width:220px;">
                            <input id="FCurDate" name="FCurDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" />
                        </td>
                        <th class="formTitle" style="width:60px;">凭证编号</th>
                        <td class="formValue">
                            <input id="FCredence" name="FCredence" type="text" class="form-control required" value="" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">来料单位</th>
                        <td class="formValue">
                            <select id="FHappenComNO" name="FHappenComNO" class="form-control required">
                            @foreach (var item in ViewBag.fhappencomList)
                            {
                                <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                            }
                            </select>
                        </td>
                        <th class="formTitle">摘要说明</th>
                        <td class="formValue">
                            <input id="FDescription" name="FDescription" type="text" class="form-control" />
                        </td>
                        <th class="formTitle">合同编号</th>
                        <td class="formValue">
                            <input id="FCertificateNo" name="FCertificateNo" type="text" class="form-control" value="" />
                        </td>
                    </tr>
                </tbody>
            </table>
            <table id="detail1" class="form detailForm" style="border:1px solid #ddd;">
                <tr>
                    <th class="formTitle" style="width:60px;">材料分类</th>
                    <td class="formValue" style="width:220px;">
                        <select id="MaterialNO" name="MaterialNO" class="form-control">
                            @foreach (var item in ViewBag.materialnoList)
                            {
                            <option value="@item.MaterialNO">@item.MaterialNO @item.MaterialName</option>
                            }
                        </select>
                    </td>
                    <th class="formTitle" style="width:60px;">材料牌号</th>
                    <td class="formValue" style="width:220px;">
                        <input id="MaterialCode" name="MaterialCode" type="text" class="form-control" value="" />
                    </td>
                    <th class="formTitle" style="width:60px;">&nbsp;</th>
                    <td class="formValue">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">材料规格</th>
                    <td class="formValue">
                        <input id="MaterialSizes" name="MaterialSizes" type="text" readonly="readonly" class="form-control " />
                    </td>
                    <th class="formTitle">标准编号</th>
                    <td class="formValue">
                        <input id="StandardNumber" name="StandardNumber" type="text" readonly="readonly" class="form-control" />
                    </td>
                    <th class="formTitle" style="width:100px;">特殊要求</th>
                    <td class="formValue">
                        <input id="MaterialDemand" name="MaterialDemand" type="text" readonly="readonly" class="form-control" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">仓库编号</th>
                    <td class="formValue">
                        <select id="FStoreNO" name="FStoreNO" class="form-control required">
                        </select>
                    </td>
                    <th class="formTitle">炉批号</th>
                    <td class="formValue">
                        <input id="FOvenNum" name="FOvenNum" type="text" class="form-control"  />
                    </td>
                    <th class="formTitle">&nbsp;</th>
                    <td class="formValue">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">仓库库位</th>
                    <td class="formValue">
                        <select id="FStoreSetNO" name="FStoreSetNO" class="form-control required"></select>
                    </td>
                    <th class="formTitle">捆包号</th>
                    <td class="formValue">
                        <input id="FBatchNo" name="FBatchNo" type="text" class="form-control"/>
                    </td>
                    <th class="formTitle">出厂日期</th>
                    <td class="formValue">
                        <input id="WagonNumber" name="WagonNumber" type="text" class="form-control input-wdatepicker" value="" onfocus="WdatePicker()" />
                    </td>
                </tr>
            </table>
            <table id="detail2" class="form detailForm" style="border: 1px solid #ddd; margin-top: 5px;">
                <tr>
                    <th class="formTitle" style="width:60px;">发交重量</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FQuantity_KP" name="FQuantity_KP" type="text" class="form-control text-right required isNumber" style="width:120px;margin-left:0px;" /><label style="margin-left:12px">KG</label>
                    </td>
                    <th class="formTitle" style="width:60px;">实际重量</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FQuantity" name="FQuantity" type="text" class="form-control text-right required isNumber" style="width:120px;margin-left:0px;" /><label style="margin-left:12px">KG</label>
                    </td>
                    <th class="formTitle" style="width:60px;">&nbsp;</th>
                    <td class="formValue">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">盘点张数</th>
                    <td class="formValue">
                        <input id="FZS_KP" name="FZS_KP" type="text" class="form-control text-right required isInteger" style="width:120px;margin-left:0px;" />
                    </td>
                    <th class="formTitle">实际张数</th>
                    <td class="formValue">
                        <input id="FZS" name="FZS" type="text" class="form-control text-right required isInteger" style="width:120px;margin-left:0px;" />
                    </td>
                    <th class="formTitle">包数数量</th>
                    <td class="formValue">
                        <input id="FConQuatity" name="FConQuatity" type="text" class="form-control text-right required digits" style="width:120px;margin-left:0px;" /><label style="margin-left:12px">件</label>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">制造单位</th>
                    <td class="formValue">
                        <select id="FProCompanyNO" name="FProCompanyNO" class="form-control">
                        @foreach (var item in ViewBag.fprocompanyList)
                        {
                            <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                        }
                        </select>
                    </td>
                    <th class="formTitle">材料单价</th>
                    <td class="formValue">
                        <input id="FPrice" name="FPrice" type="text" class="form-control text-right number" style="width:120px;margin-left:0px;" /><label style="margin-left:12px">元</label>
                    </td>
                    <th class="formTitle">材料金额</th>
                    <td class="formValue">
                        <input id="FMoney" name="FMoney" type="text" class="form-control text-right required isNumber" style="width:120px;margin-left:0px;" /><label style="margin-left:12px">元</label>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">备注说明</th>
                    <td class="formValue" colspan="5">
                        <input id="FDescription2" name="FDescription2" type="text" class="form-control" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <hr style="margin-top:5px;margin-bottom:0px;" />
    <div style="margin-left: 10px; margin-right: 10px;border-bottom:1px solid #ccc;">
        <ul id="myTab" class="nav nav-tabs" style="">
            <li class="active"><a>采购合同</a></li>
        </ul>
        <div id="myTabContent" class="tab-content" style="height:200px;">
            <div class="tab-pane fade in active" id="info2">
                <table id="gridList2"></table>
                <div id="gridPager2"></div>
            </div>
        </div>
    </div>
    <div style="text-align:right;margin-left: 10px; margin-right: 10px;padding:5px 40px;">
        <div class="btn-group" style="">
            <a id="btn_ok" class="btn btn-primary center-block btn-1" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确定</a>
        </div>
        <div class="btn-group" style="margin-left:30px;">
            <a id="btn_cancel" class="btn btn-danger center-block btn-1" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 关闭</a>
        </div>
    </div>
</div>